﻿/*********************************************
 FileName:ShowPopWnd.cpp
 ProjectName:MobileManage
 Created: mr.l
 Time: 15/7/4.
 *********************************************/

#include "GNS_PlayerMgr.h"
USING_NS_CC;
#define winsize Director::getInstance()->getVisibleSize()

GNS_PlayerMgr ::GNS_PlayerMgr()
{
    ChooseDayNum=0;
    ChooseMonNum=0;
    pCurrScene=0;
	m_GameInfoStruct.clear();

	memset(m_MyName, 0, sizeof(m_MyName));
	memset(m_MyNickName, 0, sizeof(m_MyNickName));
	memset(m_Notice, 0, sizeof(m_Notice));
}
GNS_PlayerMgr::~GNS_PlayerMgr(){

	m_mFriendList.clear();
	m_mInviteFriend.clear();
}

GNS_PlayerMgr * GNS_PlayerMgr::m_singleton=NULL;

GNS_PlayerMgr* GNS_PlayerMgr::GetInstance(){
    if (NULL ==m_singleton) {
        m_singleton = new GNS_PlayerMgr();
    }
    return m_singleton;
}

string GNS_PlayerMgr::getTwoCodeInfo(int n_index )
{
	if (n_index==0)
	{
		return m_szTwoCodeInfo;
	}
	else
	{
		return m_szTwoCodeInfoIos;
	}
	
}
void GNS_PlayerMgr::SetTwoCodeInfo(string szResText, int index)
{
	//0 = android
	//1 = ios
	if (index==0)
	{
		m_szTwoCodeInfo = szResText;
	}
	else
	{
		m_szTwoCodeInfoIos = szResText;
	}	
}

long long GNS_PlayerMgr::FindListIndex(CMD_Mail *pMailInfo)
{
	if (NULL == pMailInfo)
	{
		return 0;
	}

	switch (pMailInfo->iMailType)
	{
		case MAIL_NULL://所有
		{
			break;
		}
		default:
		{ 
			//所有邮件map列表 
			map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(pMailInfo->iMailType);
			if (itrMapAllList != m_MapAllList.end())
			{ 
				map<long long, pair<string, vector<CMD_Mail> > >::iterator iter = itrMapAllList->second.begin();
				for (; iter != itrMapAllList->second.end(); ++iter)
				{
					vector<CMD_Mail>::iterator vitr = iter->second.second.begin();
					for (; vitr != iter->second.second.end(); ++vitr)
					{
						if (pMailInfo->llRid == (*vitr).llRid)
						{
							return iter->first;
							break;
						}
					}
				}
			} 
			else
			{
				return 0;
			}

			break;
		}
	}
 
	return 0;
}


bool GNS_PlayerMgr::IsReadReceiptMail(long long llListIndex, short MailType /*= MAIL_NULL*/)
{


	switch (MailType)
	{ 
		case MAIL_FRIEND://个人信息
		{
			map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MailType);
			if (itrMapAllList != m_MapAllList.end())
			{
				map<long long, pair<string, vector<CMD_Mail> > >::iterator iter = itrMapAllList->second.find(llListIndex);
				if (iter != itrMapAllList->second.end())
				{
					vector<CMD_Mail>::iterator vitr = iter->second.second.begin();
					for (; vitr != iter->second.second.end(); ++vitr)
					{
						if (0 == (*vitr).iReadReceipt&& getMyUserIdx() != (*vitr).llUid)
						{
							return true;
							break;
						}
					}
				}
			}
			 
			break;
		} 
		case MAIL_NULL://所有
		{
			if (GetMailCount(MAIL_NULL) > 0)
			{
			   return true;
			}
			break;
		}
		default:
		{

			//所有邮件map列表 
			map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MailType);
			if (itrMapAllList != m_MapAllList.end())
			{
				map<long long, pair<string, vector<CMD_Mail> > >::iterator iter = itrMapAllList->second.find(llListIndex);
				if (iter != itrMapAllList->second.end())
				{
					vector<CMD_Mail>::iterator vitr = iter->second.second.begin();
					for (; vitr != iter->second.second.end(); ++vitr)
					{
						if (0 == (*vitr).iReadReceipt)
						{
							return true;
							break;
						}
					}
				}
			}
				   break;
		}
	}
	return false;
}

void GNS_PlayerMgr::UpdateMailToMapList(CMD_Mail* pMail)
{
	if (NULL == pMail)
	{
		return;
	}

	CMD_Mail* pMailTpm = FindMailFromMapList(pMail->llRid);
	if (pMailTpm)
	{
		*pMailTpm = *pMail;
	}

	pMailTpm = FindMail(pMail->llRid);
	if (pMailTpm)
	{
		*pMailTpm = *pMail;
	}
}

CMD_Mail * GNS_PlayerMgr::FindMailFromMapList(long long llRid)
{

	if (0 == llRid)
	{
		return 0;
	}

	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.begin();
	for (; itrMapAllList != m_MapAllList.end();++itrMapAllList)
	{
		map<long long, pair<string, vector<CMD_Mail> > >::iterator iter = itrMapAllList->second.begin();
		for (; iter != itrMapAllList->second.end(); ++iter)
		{
			vector<CMD_Mail>::iterator vitr = iter->second.second.begin();
			for (; vitr != iter->second.second.end(); ++vitr)
			{
				if (llRid == (*vitr).llRid)
				{
					return &(*vitr);
					break;
				}
			}
		}
	} 
	return NULL;
}

vector<CMD_Mail> *GNS_PlayerMgr::getSysMailList()
{ 
	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MAIL_SYS);
	if (itrVecAllList == m_allVectorMailList.end())
	{
		vector<CMD_Mail> temp;
		m_allVectorMailList[MAIL_SYS] = temp;
		itrVecAllList = m_allVectorMailList.find(MAIL_SYS);
	}
	return &itrVecAllList->second;
}

vector<CMD_Mail> *GNS_PlayerMgr::getFriendMailList()
{
	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MAIL_FRIEND);
	if (itrVecAllList == m_allVectorMailList.end())
	{
		vector<CMD_Mail> temp;
		m_allVectorMailList[MAIL_FRIEND] = temp;
		itrVecAllList = m_allVectorMailList.find(MAIL_FRIEND);
	}
	return &itrVecAllList->second;
}

vector<CMD_Mail> *GNS_PlayerMgr::getReChargeMailList()
{
	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MAIL_RECHARGE);
	if (itrVecAllList == m_allVectorMailList.end())
	{
		vector<CMD_Mail> temp;
		m_allVectorMailList[MAIL_RECHARGE] = temp;
		itrVecAllList = m_allVectorMailList.find(MAIL_RECHARGE);
	}
	return &itrVecAllList->second;
}

vector<CMD_Mail> *GNS_PlayerMgr::getShareGoldMailList()
{
	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MAIL_SHARE_GOLD);
	if (itrVecAllList == m_allVectorMailList.end())
	{
		vector<CMD_Mail> temp;
		m_allVectorMailList[MAIL_SHARE_GOLD] = temp;
		itrVecAllList = m_allVectorMailList.find(MAIL_SHARE_GOLD);
	}
	return &itrVecAllList->second;
}

vector<CMD_Mail> * GNS_PlayerMgr::getReturnExchangeGoldMailList()
{
	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MAIL_RETURN_EXCHANGE);
	if (itrVecAllList == m_allVectorMailList.end())
	{
		vector<CMD_Mail> temp;
		m_allVectorMailList[MAIL_RETURN_EXCHANGE] = temp;
		itrVecAllList = m_allVectorMailList.find(MAIL_RETURN_EXCHANGE);
	}
	return &itrVecAllList->second;
}


vector<CMD_Mail> * GNS_PlayerMgr::getDeductionMailList()
{
	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MAIL_RECHANGE_OR_DEDUCTION);
	if (itrVecAllList == m_allVectorMailList.end())
	{
		vector<CMD_Mail> temp;
		m_allVectorMailList[MAIL_RECHANGE_OR_DEDUCTION] = temp;
		itrVecAllList = m_allVectorMailList.find(MAIL_RECHANGE_OR_DEDUCTION);
	}
	return &itrVecAllList->second;
}


vector<CMD_Mail> * GNS_PlayerMgr::getDivideResult()
{

	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MAIL_DIVIDE_RESULT);
	if (itrVecAllList == m_allVectorMailList.end())
	{
		vector<CMD_Mail> temp;
		m_allVectorMailList[MAIL_DIVIDE_RESULT] = temp;
		itrVecAllList = m_allVectorMailList.find(MAIL_DIVIDE_RESULT);
	}
	return &itrVecAllList->second;
}

map<long long, pair<string, vector<CMD_Mail> > > * GNS_PlayerMgr::getMapSysLietMail()
{
	//所有邮件map列表 
	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MAIL_SYS);
	if (itrMapAllList == m_MapAllList.end())
	{
		map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
		m_MapAllList[MAIL_SYS] = tempMapPair;
		itrMapAllList = m_MapAllList.find(MAIL_SYS);

	}
	return &itrMapAllList->second;
};//保存 系统邮件列表 中每列对应的邮件

map<long long, pair<string, vector<CMD_Mail> > > * GNS_PlayerMgr::getMapFriendLietMail()
{
	//所有邮件map列表 
	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MAIL_FRIEND);
	if (itrMapAllList == m_MapAllList.end())
	{
		map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
		m_MapAllList[MAIL_FRIEND] = tempMapPair;
		itrMapAllList = m_MapAllList.find(MAIL_FRIEND);

	}
	return &itrMapAllList->second;
};//保存 个人信息列表 中每列对应的邮件

map<long long, pair<string, vector<CMD_Mail> > > * GNS_PlayerMgr::getMapReChargeMailList()
{
	//所有邮件map列表 
	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MAIL_RECHARGE);
	if (itrMapAllList == m_MapAllList.end())
	{
		map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
		m_MapAllList[MAIL_RECHARGE] = tempMapPair;
		itrMapAllList = m_MapAllList.find(MAIL_RECHARGE);

	}
	return &itrMapAllList->second;
};//保存 点卡充值邮件列表 中每列对应的邮件

map<long long, pair<string, vector<CMD_Mail> > > * GNS_PlayerMgr::getMapShareGoldMailList()
{
	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MAIL_SHARE_GOLD);
	if (itrMapAllList == m_MapAllList.end())
	{
		map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
		m_MapAllList[MAIL_SHARE_GOLD] = tempMapPair;
		itrMapAllList = m_MapAllList.find(MAIL_SHARE_GOLD);

	}
	return &itrMapAllList->second;
};//保存 分享金币邮件列表 中每列对应的邮件

map<long long, pair<string, vector<CMD_Mail> > > * GNS_PlayerMgr::getMapReturnExchangeGoldMailList()
{
	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MAIL_RETURN_EXCHANGE);
	if (itrMapAllList == m_MapAllList.end())
	{
		map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
		m_MapAllList[MAIL_RETURN_EXCHANGE] = tempMapPair;
		itrMapAllList = m_MapAllList.find(MAIL_RETURN_EXCHANGE);

	}
	return &itrMapAllList->second;
}


map<long long, pair<string, vector<CMD_Mail> > > * GNS_PlayerMgr::getMapDeductionMailList()
{
	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MAIL_RECHANGE_OR_DEDUCTION);
	if (itrMapAllList == m_MapAllList.end())
	{
		map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
		m_MapAllList[MAIL_RECHANGE_OR_DEDUCTION] = tempMapPair;
		itrMapAllList = m_MapAllList.find(MAIL_RECHANGE_OR_DEDUCTION);

	}
	return &itrMapAllList->second;
}


map<long long, pair<string, vector<CMD_Mail> > > * GNS_PlayerMgr::getMapDivideResultMailList()
{

	map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MAIL_DIVIDE_RESULT);
	if (itrMapAllList == m_MapAllList.end())
	{
		map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
		m_MapAllList[MAIL_DIVIDE_RESULT] = tempMapPair;
		itrMapAllList = m_MapAllList.find(MAIL_DIVIDE_RESULT);

	}
	return &itrMapAllList->second;
}

CMD_Mail * GNS_PlayerMgr::FindMail(long long llRid)
{

	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.begin();
	for (; itrVecAllList != m_allVectorMailList.end();++itrVecAllList)
	{
		vector<CMD_Mail>::iterator iter = itrVecAllList->second.begin();
		for (; iter != itrVecAllList->second.end(); iter++)
		{
			if (llRid == iter->llRid)
			{
				return &(*iter);
			}
		}
	}
	 
	return NULL;
}


vector<CMD_Mail> * GNS_PlayerMgr::FindMail(long long ListIndex, short MailType)
{

	switch (MailType)
	{ 
		case MAIL_NULL://所有
		{
						   break;
		}
		default:
		{
			//所有邮件map列表 
			map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(MailType);
			if (itrMapAllList != m_MapAllList.end())
			{
				map<long long, pair<string, vector<CMD_Mail> > >::iterator iter = itrMapAllList->second.find(ListIndex);
				if (iter != itrMapAllList->second.end())
				{
					return &(iter->second.second);
				}
			}

				   break;
		}
	}
	return NULL;
}

int GNS_PlayerMgr::GetMailCount(short MailType /*= MAIL_NULL*/)
{
	int iMailCount = 0;
	 
	switch (MailType)
	{
		case MAIL_SYS: //系统邮件
		{
			int nShowSysMailCount = 0;

			//所有邮件列表
			map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MailType);
			if (itrVecAllList != m_allVectorMailList.end())
			{
				vector<CMD_Mail>::iterator iter = itrVecAllList->second.begin();
				for (; iter != itrVecAllList->second.end(); iter++)
				{
					if (0 == iter->iReadReceipt)
					{
						iMailCount++;
						//if (iMailCount >= 30)
						if (iMailCount >= 80)
						{
							break;
						}
					}
					//if (++nShowSysMailCount >= 30)
					if (++nShowSysMailCount >= 80)
					{
						break;
					}
				}
			}
						    
						   
			break;
		} 
		case MAIL_FRIEND://个人信息
		{ 
			//所有邮件列表
			map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MailType);
			if (itrVecAllList != m_allVectorMailList.end())
			{
				vector<CMD_Mail>::iterator iter = itrVecAllList->second.begin();
				for (; iter != itrVecAllList->second.end(); iter++)
				{
					if (0 == iter->iReadReceipt && getMyUserIdx() != iter->llUid)
					{
						iMailCount++;
					}
				}
			}
			 
			 break;
		} 
		//case MAIL_DIVIDE_RESULT: // 下线贡献的金币 邮件
		//{ 
		//	//所有邮件列表
		//	map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MailType);
		//	if (itrVecAllList != m_allVectorMailList.end())
		//	{

		//		iMailCount ++;

		//		//vector<CMD_Mail>::iterator iter = itrVecAllList->second.begin();
		//		//for (; iter != itrVecAllList->second.end(); iter++)
		//		//{
		//		//	if (0 == iter->iReadReceipt)
		//		//	{
		//		//		iMailCount++;
		//		//	}
		//		//}
		//	} 
		//	break;
		//}
		case MAIL_NULL://所有
		{ 
			int nShowSysMailCount = 0;

			//所有邮件列表
			map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.begin();
			for (; itrVecAllList != m_allVectorMailList.end();++itrVecAllList)
			{
				vector<CMD_Mail>::iterator iter = itrVecAllList->second.begin();
				for (; iter != itrVecAllList->second.end(); iter++)
				{
					if (0 == iter->iReadReceipt)
					{
						if (MAIL_FRIEND == itrVecAllList->first &&  getMyUserIdx() == iter->llUid)
						{
							continue;
						}

						iMailCount++;
						if (MAIL_SYS == itrVecAllList->first)
						{
							//if (iMailCount >= 30)
							if (iMailCount >= 80)
							{
								break;
							}
						}
					}

					if (MAIL_SYS == itrVecAllList->first)
					{
						//if (++nShowSysMailCount >= 30)
						if (++nShowSysMailCount >= 80)
						{
							break;
						}
					}
				}
			}

			 
			break;
		}
		default:
		{

			//所有邮件列表
			map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(MailType);
			if (itrVecAllList != m_allVectorMailList.end())
			{
				vector<CMD_Mail>::iterator iter = itrVecAllList->second.begin();
				for (; iter != itrVecAllList->second.end(); iter++)
				{
					if (0 == iter->iReadReceipt)
					{
						iMailCount++;
					}
				}
			}
				   break;
		}
	}
	return iMailCount;
}

void GNS_PlayerMgr::DeleMailList(CMD_Mail* pMail)
{

	if (NULL == pMail)
	{
		return;
	}

	switch (pMail->iMailType)
	{ 
		default:
		{

			//所有邮件列表
			map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(pMail->iMailType);
			if (itrVecAllList != m_allVectorMailList.end())
			{
				vector<CMD_Mail>::iterator iter = itrVecAllList->second.begin(); 
				while (iter != itrVecAllList->second.end())
				{
					if (iter->llRid == pMail->llRid)
					{ 
						map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(pMail->iMailType);
						if (itrMapAllList != m_MapAllList.end())
						{
							map<long long, pair<string, vector<CMD_Mail> > >::iterator itrMap = itrMapAllList->second.begin(); 
							while (itrMap != itrMapAllList->second.end())
							{
								bool bFind = false;
								vector<CMD_Mail>::iterator vItr = itrMap->second.second.begin(); 
								while (vItr != itrMap->second.second.end())
								{
									if ((*vItr).llRid == pMail->llRid)
									{
										// 删除那个对应的邮件
										vItr = itrMap->second.second.erase(vItr);
										 
										continue;
									}
									++vItr;
								} 

								if (itrMap->second.second.empty())
								{
									itrMap = itrMapAllList->second.erase(itrMap);
								}
								else
								{
									itrMap++;
								}
							}

						}

						iter =itrVecAllList->second.erase(iter);
						 
					}
					else
					{
						iter++; 
					}
				}
			}

				   break;
		}
	}
}
void GNS_PlayerMgr::AddMailList(CMD_Mail* pMail)
{
	if (NULL == pMail)
	{
		return;
	} 

	switch (pMail->iMailType)
	{ 
		case MAIL_FRIEND://个人信息
		{

			//所有邮件列表
			map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(pMail->iMailType);
			if (itrVecAllList == m_allVectorMailList.end())
			{
				vector<CMD_Mail> temp;
				m_allVectorMailList[pMail->iMailType] = temp;
				itrVecAllList = m_allVectorMailList.find(pMail->iMailType);
			}
			 
			itrVecAllList->second.push_back(*pMail);

			// 降序排序
			sort(itrVecAllList->second.begin(), itrVecAllList->second.end(), greater<CMD_Mail>()); 
			// 每个邮件id 只显示一条记录在一个列表行上面
			long long llNewID = 0;
			string strName = "";
			GetFriendListIndex(pMail, llNewID, strName);
			//所有邮件map列表 
			map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(pMail->iMailType);
			if (itrMapAllList == m_MapAllList.end())
			{
				map<long long, pair<string, vector<CMD_Mail> > > tempMapPair;
				m_MapAllList[pMail->iMailType] = tempMapPair;
				itrMapAllList = m_MapAllList.find(pMail->iMailType);

			}

			//把属于这一列的邮件保存
			map<long long, pair<string, vector<CMD_Mail> > >::iterator itr = itrMapAllList->second.find(llNewID);
			if (itrMapAllList->second.end() != itr)
			{
				itr->second.second.push_back(*pMail);
				// 降序排序
				sort(itr->second.second.begin(), itr->second.second.end(), greater<CMD_Mail>());
			}
			else
			{ 
				vector<CMD_Mail> tmp_VecMail;
				tmp_VecMail.push_back(*pMail);
				pair<string, vector<CMD_Mail> > pairMail(strName, tmp_VecMail);
				itrMapAllList->second.insert(make_pair(llNewID, pairMail));
			}
			/// 
							 break;
		}
		 
		default:
		{
			//所有邮件列表
			map<int, vector<CMD_Mail> >::iterator itrVecAllList = m_allVectorMailList.find(pMail->iMailType);
			if (itrVecAllList == m_allVectorMailList.end())
			{
				vector<CMD_Mail> temp;
				m_allVectorMailList[pMail->iMailType] = temp;
				itrVecAllList = m_allVectorMailList.find(pMail->iMailType);
			}

			if (pMail->llTid != m_MyUserIdx)
			{
				return;
			}
			itrVecAllList->second.push_back(*pMail);

			// 降序排序
			sort(itrVecAllList->second.begin(), itrVecAllList->second.end(), greater<CMD_Mail>());
			// 每个邮件id 只显示一条记录在一个列表行上面
			long long llNewID = pMail->llRid;


			//所有邮件map列表 
			map<int, map<long long, pair<string, vector<CMD_Mail> > > >::iterator itrMapAllList = m_MapAllList.find(pMail->iMailType);
			if (itrMapAllList == m_MapAllList.end())
			{  
				map<long long, pair<string, vector<CMD_Mail> > > tempMapPair; 
				m_MapAllList[pMail->iMailType] = tempMapPair;
			 itrMapAllList = m_MapAllList.find(pMail->iMailType);

			} 
			 

			//把属于这一列的邮件保存
			map<long long, pair<string, vector<CMD_Mail> > >::iterator itr = itrMapAllList->second.find(llNewID);
			if (itrMapAllList->second.end() != itr)
			{
				itr->second.second.push_back(*pMail);
				// 降序排序
				sort(itr->second.second.begin(), itr->second.second.end(), greater<CMD_Mail>());
			}
			else
			{
				string strName = pMail->szSenderName;
				vector<CMD_Mail> tmp_VecMail;
				tmp_VecMail.push_back(*pMail);
				pair<string, vector<CMD_Mail> > pairMail(strName, tmp_VecMail);
				itrMapAllList->second.insert(make_pair(llNewID, pairMail));
			}

			if (pMail->iMailType == MAIL_SYS)
			{ 
				//if (m_MapSysLietMail.size() > 30)
				if (itrMapAllList->second.size() > 80)
				{
					vector<CMD_Mail> tempDelVec;
					map<long long, pair<string, vector<CMD_Mail> > >::iterator delItr = itrMapAllList->second.begin();
					if (delItr != itrMapAllList->second.end())
					{
						std::copy(delItr->second.second.begin(), delItr->second.second.end(), std::back_inserter(tempDelVec));
					}

					vector<CMD_Mail>::iterator delvecitr = tempDelVec.begin();

					for (; delvecitr != tempDelVec.end(); ++delvecitr)
					{
						DeleMailList(&(*delvecitr));
					}

				}
			}
			break;
		}
	}
}

void GNS_PlayerMgr::GetFriendListIndex(CMD_Mail *pMailInfo, long long &llListIndex, string &MailName)
{
	if (NULL == pMailInfo)
	{
		llListIndex = -1;
		MailName = "";
		return;
	}
	// 每个玩家只显示一条记录 

	if (pMailInfo->llUid != m_MyUserIdx && pMailInfo->llTid == getMyUserIdx())
	{//发邮件人是别人，收件人是自己
		//ok通过
		llListIndex = pMailInfo->llUid;
		MailName = pMailInfo->szSenderName;
	}
	else if (pMailInfo->llUid == m_MyUserIdx && pMailInfo->llTid != getMyUserIdx())
	{//发件人是自己，收件人是别人。 
		llListIndex = pMailInfo->llTid;
		MailName = pMailInfo->szAddresseeName;
	}
	else if (pMailInfo->llUid == m_MyUserIdx&& pMailInfo->llTid == getMyUserIdx())
	{ //收发邮件都是自己 
		llListIndex = pMailInfo->llUid;
		MailName = pMailInfo->szSenderName;
	}
	else
	{
		llListIndex = -1;
		MailName = "";
	}

}

void GNS_PlayerMgr::GetMaxMailTypeCount(short &MailType, int &nCount)
{
	map<int, short> mapMaxCount;
	//系统未读邮件总数
	int ncount = GetMailCount(MAIL_SYS);
	mapMaxCount[ncount] = MAIL_SYS;

	//个人未读邮件总数
	ncount = GetMailCount(MAIL_FRIEND);
	mapMaxCount[ncount] = MAIL_FRIEND;

	//礼品未读邮件总数
	ncount = GetMailCount(MAIL_SHARE_GOLD);
	ncount += GetMailCount(MAIL_RECHARGE);
	ncount += GetMailCount(MAIL_RETURN_EXCHANGE);
	ncount += GetMailCount(MAIL_RECHANGE_OR_DEDUCTION);
	ncount += GetMailCount(MAIL_DIVIDE_RESULT);
	//MAIL_SHARE_GOLD 做 礼品未读邮件 人大代表了。
	mapMaxCount[ncount] = MAIL_SHARE_GOLD;

	map<int, short>::reverse_iterator itr = mapMaxCount.rbegin();

	if (itr != mapMaxCount.rend())
	{
		nCount = itr->first;
		MailType = itr->second;
	}
}

int GNS_PlayerMgr::GetMaxGiftMailCount()
{
	//礼品未读邮件总数
	int ncount = 0;
	ncount = GetMailCount(MAIL_SHARE_GOLD);
	ncount += GetMailCount(MAIL_RECHARGE);
	ncount += GetMailCount(MAIL_RETURN_EXCHANGE);
	ncount += GetMailCount(MAIL_RECHANGE_OR_DEDUCTION);
	ncount += GetMailCount(MAIL_DIVIDE_RESULT);
	return 	ncount;
}


void GNS_PlayerMgr::SetSearchFriendData(CMD_FriendData *& pFriendData)
{
	if (pFriendData->lFriendUserId == GNS_PlayerMgr::GetInstance()->getMyUserIdx())
		return;

	CMD_FriendData friendData;
	memcpy(&friendData, pFriendData, sizeof(friendData));
	m_mSearchFriend.insert(make_pair(friendData.lFriendUserId, friendData));
}

void GNS_PlayerMgr::resetAll()
{ 
	m_allVectorMailList.clear();
	m_mInviteFriend.clear();
	m_mFriendList.clear();
	m_GameInfoStruct.clear();

 
	m_MapAllList.clear();
	m_mRankList.clear();
	m_mSearchFriend.clear();

}

int GNS_PlayerMgr::getAllMapListMailcount()
{ 
	map<long long, pair<string, vector<CMD_Mail> > > *pSysL = getMapSysLietMail();// //保存 系统邮件列表 中每列对应的邮件
	map<long long, pair<string, vector<CMD_Mail> > > *pFriL = getMapFriendLietMail();// //保存 个人信息列表 中每列对应的邮件
	map<long long, pair<string, vector<CMD_Mail> > > *pReCharge = getMapReChargeMailList();// //保存 点卡充值邮件列表 中每列对应的邮件
	map<long long, pair<string, vector<CMD_Mail> > > *pShareGold = getMapShareGoldMailList();// //保存 分享金币邮件列表 中每列对应的邮件
	map<long long, pair<string, vector<CMD_Mail> > > *pReturn = getMapReturnExchangeGoldMailList();//保存 返还兑换金币邮件列表 中每列对应的邮件
	map<long long, pair<string, vector<CMD_Mail> > > *pDeduct = getMapDeductionMailList();//保存 扣除金币邮件列表 中每列对应的邮件
	map<long long, pair<string, vector<CMD_Mail> > > *pDivide = getMapDivideResultMailList();//保存 扣除金币邮件列表 中每列对应的邮件
	 //系统邮件
	int ncountSys = 0;
	int ncountFriend = 0;
	int ncountReCharge = 0;
	int ncountShareGold =0; 

	if (NULL != pSysL)
	{
		ncountSys = pSysL->size();
	}

	if (NULL != pFriL)
	{
		ncountFriend = pFriL->size();
	}

	if (NULL != pReCharge)
	{
		ncountReCharge = pReCharge->size();
	}

	if (NULL != pShareGold)
	{
		ncountShareGold += pShareGold->size();
	}

	if (NULL != pReturn)
	{
		ncountShareGold += pReturn->size();
	}

	if (NULL != pDeduct)
	{
		ncountShareGold += pDeduct->size();
	}

	if (NULL != pDivide)
	{
		ncountShareGold += pDivide->size();
	}

	return ncountSys > 80 ? 80 : ncountSys + ncountFriend + ncountReCharge + ncountShareGold;
}

